<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.tmptSource.mapper<#if datasource=="dsB">biz</#if>.${classNameFirstWordUpper}Mapper" >
    <resultMap id="BaseResultMap" type="com.tmptSource.bean.${classNameFirstWordUpper}" >
        <id column="${primaryKey}" property="${primaryKey}" jdbcType="BIGINT" />
        <#list columnList as column>
        <#if column.isPrimaryKey=="false">
        <result column="${column.columnName}" property="${column.propertyName}" jdbcType="${column.columnType4MyBatis}" />
        </#if>
        </#list>
    </resultMap>
    <sql id="Base_Column_List" >
        ${columnStr}
    </sql>
    <sql id="Page_Sql">
        <if test="page != null" >
            <if test="page.pageSize != 0">
                <#--limit #${r"{"}pageSize,jdbcType=INTEGER} offset #${r"{"}pageSize,jdbcType=INTEGER} * (#${r"{"}pageCurrent,jdbcType=INTEGER})-->
                limit #${r"{"}page.pageIndex,jdbcType=INTEGER},#${r"{"}page.pageSize,jdbcType=INTEGER}
            </if>
        </if>
    </sql>
    <sql id="Select_List_Where">
        <where>
            <#assign hasDeleteFlag="false">

            <if test="bean != null" >
            <#list conditionColumnMapList as conditionColumn>
            <#if  conditionColumn.columnType4JavaEncap=='Timestamp'>
                <if test="bean.${conditionColumn.propertyName}_Start != null" >
                    and ${conditionColumn.columnNameAlias} <![CDATA[ >= ]]> #${r"{bean."}${conditionColumn.propertyName}_Start,jdbcType=${conditionColumn.columnType4MyBatis}}
                </if>
                <if test="bean.${conditionColumn.propertyName}_End != null" >
                    and ${conditionColumn.columnNameAlias} <![CDATA[ < ]]> #${r"{bean."}${conditionColumn.propertyName}_End,jdbcType=${conditionColumn.columnType4MyBatis}}
                </if>
                <if test="bean.${conditionColumn.propertyName} != null" >
                    and ${conditionColumn.columnNameAlias} <![CDATA[ = ]]> #${r"{bean."}${conditionColumn.propertyName},jdbcType=${conditionColumn.columnType4MyBatis}}

                    <#--and ${conditionColumn.columnNameAlias} <![CDATA[ >= ]]> #${r"{bean."}${conditionColumn.propertyName},jdbcType=${conditionColumn.columnType4MyBatis}}
                    and ${conditionColumn.columnNameAlias} <![CDATA[ < ]]> #${r"{bean."}${conditionColumn.propertyName}_235959999,jdbcType=${conditionColumn.columnType4MyBatis}}-->
                </if>
            <#elseif conditionColumn.columnDbType=='int' || conditionColumn.columnDbType=='long' || conditionColumn.columnDbType=='bigint'
                    || conditionColumn.columnDbType=='double' || conditionColumn.columnDbType=='numeric' >
                <#if conditionColumn.queryType=='between'>
                <if test="bean.${conditionColumn.propertyName}_Start != null">
                    and ${conditionColumn.columnNameAlias} <![CDATA[ >= ]]> #${r"{bean."}${conditionColumn.propertyName}_Start,jdbcType=${conditionColumn.columnType4MyBatis}}
                </if>
                <if test="bean.${conditionColumn.propertyName}_End != null">
                    and ${conditionColumn.columnNameAlias} <![CDATA[ < ]]> #${r"{bean."}${conditionColumn.propertyName}_End,jdbcType=${conditionColumn.columnType4MyBatis}}
                </if>
                </#if>
                <if test="bean.${conditionColumn.propertyName} != null">
                    and ${conditionColumn.columnNameAlias} = #${r"{bean."}${conditionColumn.propertyName},jdbcType=${conditionColumn.columnType4MyBatis}}
                </if>
            <#else>
                <if test="bean.${conditionColumn.propertyName} != null" >
                    and ${conditionColumn.columnNameAlias} ${conditionColumn.queryTypeLinkSign} #${r"{bean."}${conditionColumn.propertyName},jdbcType=${conditionColumn.columnType4MyBatis}}
                </if>
            </#if>
            <#if conditionColumn.propertyName?lower_case=='deleteflag'><#assign hasDeleteFlag="true"></#if>
            </#list>
            </if>
            <#--数据边界-->
            <if test="dataParam != null" >
                <if test="dataParam.dataLimitType != null">
                    <if test="dataParam.dataLimitType == dataParam.OnlyMySelf" >
                        and <#if tableAliasName?exists && tableAliasName!="">${tableAliasName}.</#if>createman_id = ${r"#"}{dataParam.userId,jdbcType=INTEGER}
                    </if>
                    <if test="dataParam.dataLimitType == dataParam.LowPost" >
                        and <#if tableAliasName?exists && tableAliasName!="">${tableAliasName}.</#if>createman_id in (select low_user_id from a2low_user_tmp where user_id=${r"#"}{dataParam.userId,jdbcType=INTEGER} and user_type=1)
                    </if>
                    <if test="dataParam.dataLimitType == dataParam.SamePostAndLowPost" >
                        and <#if tableAliasName?exists && tableAliasName!="">${tableAliasName}.</#if>createman_id in (select low_user_id from a2low_user_tmp where user_id=${r"#"}{dataParam.userId,jdbcType=INTEGER})
                    </if>
                    <if test="dataParam.dataLimitType == dataParam.LowCompany" >
                        and <#if tableAliasName?exists && tableAliasName!="">${tableAliasName}.</#if>company_id = ${r"#"}{dataParam.companyId,jdbcType=INTEGER}
                    </if>
                </if>
            </if>

            <#if hasDeleteFlag=='false'>
            <#if tableAliasName?exists && tableAliasName!="">
                and ${tableAliasName}.deleteFlag=0
            <#else>
                and deleteFlag=0
            </#if>
            </#if>
        </where>
    </sql>
    <sql id="OrderBy_Sql">
        <if test="page != null" >
            <if test="page.sortColumn != null and page.sortColumn != '' and page.sortOrder != null and page.sortOrder != ''">
                <#if tableAliasName?exists && tableAliasName!="">
                    order by ${tableAliasName}.${r"${"}page.sortColumn}  ${r"${"}page.sortOrder}
                <#else>
                    order by ${r"${"}page.sortColumn}  ${r"${"}page.sortOrder}
                </#if>
            </if>
        </if>
    </sql>


    <#list columnList as column>
    <#if column.dataResource?exists && column.dataResource==2 && column.optionsSql?exists && column.optionsSql!='' >
    <!-- 页面上查询列的值，动态加载，sql语句读数据库配置而来 -->
    <select id="select4${column.propertyName}" resultType="java.util.Map">
        ${column.optionsSql}
    </select>
    </#if>
    </#list>


    <select id="selectByPagination" resultMap="BaseResultMap" parameterType="java.util.Map" >
        select
        <include refid="Base_Column_List" />
        from ${tableNameSql}
        <include refid="Select_List_Where" />
        <include refid="OrderBy_Sql" />
        <include refid="Page_Sql" />
    </select>

    <select id="selectSum" resultMap="BaseResultMap" parameterType="java.util.Map" >
        select
        <#if columnSumStr?length!=0>
            ${columnSumStr}
        <#else>
            count(0)
        </#if>
        from ${tableNameSql}
        <include refid="Select_List_Where" />
    </select>

    <select id="selectListCount" resultType="java.lang.Integer" parameterType="java.util.Map" >
        select count(*)
        from ${tableNameSql}
        <include refid="Select_List_Where" />
    </select>

    <select id="selectAll" resultMap="BaseResultMap" parameterType="java.util.Map">
        select
        <include refid="Base_Column_List" />
        from ${tableNameSql}
        <include refid="Select_List_Where" />
        <include refid="OrderBy_Sql" />
    </select>

    <select id="selectById" resultMap="BaseResultMap" >
        select
        <include refid="Base_Column_List" />
        from ${tableNameSql}
        where ${primaryKey} = ${r"#{"}${primaryKey},jdbcType=BIGINT}
    </select>

    <delete id="deleteById" parameterType="java.util.Map" >
        update ${tableName}
        set  deleteflag =1,modifyman=${r"#{"}modifyman,jdbcType=VARCHAR},modifydate=${r"#{"}modifydate,jdbcType=TIMESTAMP}
        where ${primaryKey} = ${r"#{"}${primaryKey},jdbcType=INTEGER}
    </delete>

    <insert id="insert" useGeneratedKeys="true" keyProperty="${primaryKey}"  parameterType="com.tmptSource.bean.${classNameFirstWordUpper}" >
        insert into ${tableName}
        (${canAddColumnStr},createman_id,createman,createdate,company_id
        )
        values (${canAddColumnValueStr},${r"#{"}createmanId,jdbcType=VARCHAR},${r"#{"}createman,jdbcType=VARCHAR}
            ,${r"#{"}createdate,jdbcType=TIMESTAMP}, ${r"#{"}companyId,jdbcType=TIMESTAMP}
        )
    </insert>

    <update id="updateById" parameterType="com.tmptSource.bean.${classNameFirstWordUpper}" >
        update ${tableName}
        set ${CanEditColumnStr},modifyman_id=${r"#{"}modifymanId,jdbcType=VARCHAR},modifyman=${r"#{"}modifyman,jdbcType=VARCHAR},modifydate=${r"#{"}modifydate,jdbcType=TIMESTAMP}
        where ${primaryKey} = ${r"#{"}${primaryKey},jdbcType=BIGINT}
    </update>


<#--
<insert id="insert" parameterType="com.runtong.agri.bmcore.persistence.models.right.TInfoCompany" >
 insert into t_info_company (company_id, company_name, company_code,
 company_type, delete_flag, create_userid,
 create_time, update_userid, update_time
 )
 values (#{companyId,jdbcType=INTEGER}, #{companyName,jdbcType=VARCHAR}, #{companyCode,jdbcType=VARCHAR},
#{companyType,jdbcType=VARCHAR}, #{deleteFlag,jdbcType=BIGINT}, #{createUserid,jdbcType=BIGINT},
#{createTime,jdbcType=TIMESTAMP}, #{updateUserid,jdbcType=BIGINT}, #{updateTime,jdbcType=TIMESTAMP}
 )
</insert>
<insert id="insertSelective" parameterType="com.runtong.agri.bmcore.persistence.models.right.TInfoCompany" >
 insert into t_info_company
 <trim prefix="(" suffix=")" suffixOverrides="," >
     <if test="companyId != null" >
         company_id,
     </if>
     <if test="companyName != null" >
         company_name,
     </if>
     <if test="companyCode != null" >
         company_code,
     </if>
     <if test="companyType != null" >
         company_type,
     </if>
     <if test="deleteFlag != null" >
         delete_flag,
     </if>
     <if test="createUserid != null" >
         create_userid,
     </if>
     <if test="createTime != null" >
         create_time,
     </if>
     <if test="updateUserid != null" >
         update_userid,
     </if>
     <if test="updateTime != null" >
         update_time,
     </if>
 </trim>
 <trim prefix="values (" suffix=")" suffixOverrides="," >
     <if test="companyId != null" >
     #{companyId,jdbcType=INTEGER},
     </if>
     <if test="companyName != null" >
     #{companyName,jdbcType=VARCHAR},
     </if>
     <if test="companyCode != null" >
     #{companyCode,jdbcType=VARCHAR},
     </if>
     <if test="companyType != null" >
     #{companyType,jdbcType=VARCHAR},
     </if>
     <if test="deleteFlag != null" >
     #{deleteFlag,jdbcType=BIGINT},
     </if>
     <if test="createUserid != null" >
     #{createUserid,jdbcType=BIGINT},
     </if>
     <if test="createTime != null" >
     #{createTime,jdbcType=TIMESTAMP},
     </if>
     <if test="updateUserid != null" >
     #{updateUserid,jdbcType=BIGINT},
     </if>
     <if test="updateTime != null" >
     #{updateTime,jdbcType=TIMESTAMP},
     </if>
 </trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.runtong.agri.bmcore.persistence.models.right.TInfoCompany" >
 update t_info_company
 <set >
     <if test="companyName != null" >
         company_name = #{companyName,jdbcType=VARCHAR},
     </if>
     <if test="companyCode != null" >
         company_code = #{companyCode,jdbcType=VARCHAR},
     </if>
     <if test="companyType != null" >
         company_type = #{companyType,jdbcType=VARCHAR},
     </if>
     <if test="deleteFlag != null" >
         delete_flag = #{deleteFlag,jdbcType=BIGINT},
     </if>
     <if test="createUserid != null" >
         create_userid = #{createUserid,jdbcType=BIGINT},
     </if>
     <if test="createTime != null" >
         create_time = #{createTime,jdbcType=TIMESTAMP},
     </if>
     <if test="updateUserid != null" >
         update_userid = #{updateUserid,jdbcType=BIGINT},
     </if>
     <if test="updateTime != null" >
         update_time = #{updateTime,jdbcType=TIMESTAMP},
     </if>
 </set>
 where company_id = #{companyId,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.runtong.agri.bmcore.persistence.models.right.TInfoCompany" >
 update t_info_company
 set company_name = #{companyName,jdbcType=VARCHAR},
 company_code = #{companyCode,jdbcType=VARCHAR},
 company_type = #{companyType,jdbcType=VARCHAR},
 delete_flag = #{deleteFlag,jdbcType=BIGINT},
 create_userid = #{createUserid,jdbcType=BIGINT},
 create_time = #{createTime,jdbcType=TIMESTAMP},
 update_userid = #{updateUserid,jdbcType=BIGINT},
 update_time = #{updateTime,jdbcType=TIMESTAMP}
 where company_id = #{companyId,jdbcType=INTEGER}
</update>-->
</mapper>